#ifndef __WINCONTAINER_H__
#define __WINCONTAINER_H__

typedef void (Delegater::*OnWinCreateFunc)(Size size);
typedef void (Delegater::*OnWinSizeFunc)(Size size);
typedef void (Delegater::*OnWinCloseFunc)();
typedef void (Delegater::*OnWinMouseFunc)(Point pos);

class WinContainer : public CWindowImpl<WinContainer, CWindow,
	CWinTraits<WS_SYSMENU | WS_MINIMIZEBOX /*| WS_MAXIMIZEBOX | WS_SIZEBOX*/>>
{
public:
	DECLARE_WND_CLASS(L"BeanWin")

	BEGIN_MSG_MAP(WinContainer)
		MESSAGE_HANDLER(WM_CREATE, MsgOnCreate);
		MESSAGE_HANDLER(WM_SIZE, MsgOnSize);
		MESSAGE_HANDLER(WM_ERASEBKGND, MsgOnEraseBkg);
		MESSAGE_HANDLER(WM_CLOSE, MsgOnClose);
		MESSAGE_HANDLER(WM_MOUSEMOVE, MsgOnMouseMove);
		MESSAGE_HANDLER(WM_LBUTTONDOWN, MsgOnMouseLButtonDown);
		MESSAGE_HANDLER(WM_LBUTTONUP, MsgOnMouseLButtonUp);
	END_MSG_MAP()
public:
	HWND CreateEx(std::wstring wstrCaption, int width, int height);	//will center
	HWND CreateEx(std::wstring wstrCaption, RECT rc);

	Size GetWinSize();
	void CloseWindow();

private:
	LRESULT MsgOnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
	LRESULT MsgOnSize(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
	LRESULT MsgOnEraseBkg(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
	LRESULT MsgOnClose(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
	LRESULT MsgOnMouseMove(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
	LRESULT MsgOnMouseLButtonDown(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
	LRESULT MsgOnMouseLButtonUp(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);

	void GetClientCursorPos(LPPOINT pt);
public:
	Event<OnWinCreateFunc> OnWinCreate;
	Event<OnWinSizeFunc> OnWinSize;
	Event<OnWinCloseFunc> OnWinClose;
	Event<OnWinMouseFunc> OnWinMouseMove;
	Event<OnWinMouseFunc> OnWinMouseLButtonDown;
	Event<OnWinMouseFunc> OnWinMouseLButtonUp;
};

#endif